package com.cntcdt.api.resources.base;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.restlet.data.MediaType;
import org.restlet.resource.ServerResource;

public class ServerResourceExtension extends ServerResource {

    public ServerResourceExtension(){}
    
    protected MediaType getMediaType(){
	MediaType mediaType;
	Map<String,Object> paramMap = getRequest().getAttributes();
	
        String format = paramMap.get("format") == null ? "" : (String) paramMap
                .get("format");
        
        if (StringUtils.equalsIgnoreCase(format, "rss"))
        {
            mediaType = MediaType.valueOf("rss");
        } else if (StringUtils.equalsIgnoreCase(format, "json"))
        {
            mediaType = MediaType.APPLICATION_JSON;
        } else if (StringUtils.equalsIgnoreCase(format, "atom"))
        {
            mediaType = MediaType.APPLICATION_ATOMPUB_SERVICE;
        } else
        {
            mediaType = MediaType.APPLICATION_XML;
        }
        return mediaType;
    }
}
